//
//  PrefixHeader.pch
//  DreamRoomage
//
//  Created by wjy on 15/9/7.
//  Copyright (c) 2015年 wjy. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

#pragma mark - 初始化
- (instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
#pragma mark - 遍历构造器
+ (instancetype)baseModelWithDic:(NSDictionary *)dic
{
    // 利用多态创建
    id objc = [[[self class] alloc] initWithDic:dic];
    return objc;
}
+ (NSMutableArray *)arrayWithModelByArray:(NSArray *)array
{
    // 创建一个数组 存放model
    NSMutableArray *arr = [NSMutableArray array];
    // 遍历数组
    for (NSDictionary *dic in array) {
        //模仿系统创建自动释放池
        @autoreleasepool {
            
            id model = [[self class] baseModelWithDic:dic];
            [arr addObject:model];
        }
    }
    return arr;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}
- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}

@end
